<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Admin_Setting extends CI_Controller {
	
	function __construct() {
        parent::__construct();	
		$this->isLogin();	
		$this->load->model('setting_model');
		$this->num_post=10;
	}
	
	function isLogin(){
		$login=$this->session->userdata('isLogin');
		if(! isset($login)||$login != true){
			$this->session->set_flashdata('error_login', 'Untuk Mengakses Admin Anda Harus Login!');
			redirect('login');	
		}
	}
	
	function seo(){
		$data['main_view']='setting/main';
		$data['hasil']=$this->setting_model->seo();
		$this->load->view('admin_template',$data);
	}

	function view_add(){
		$data['main_view']='setting/view_add';
		$this->load->view('admin_template',$data);
	}
	
	function proses_add(){
		$judul=$this->input->post('judul');
		$konten=$this->input->post('konten');
		
		
		if($query=$this->setting_model->insert_data($judul)){
			$this->session->set_flashdata('pesan', 'Data Sukses Ditambah');
			redirect('admin_setting');
			
		}
	}
	
	function view_edit($id){
		$data['main_view']='setting/view_edit';
		$data['hasil']=$this->setting_model->get_detail_data($id);
		$this->load->view('admin_template',$data);
	}
	
	function proses_update(){
		$konten=$this->input->post('konten');
		$id=$this->input->post('id');
		if($query=$this->setting_model->update_data($id,$konten)){
			$this->session->set_flashdata('pesan', 'Data Sukses Ditambah');
			redirect('admin_setting');
			
		}
	}
	
	function delete($id){
		$this->setting_model->delete_data($id);
		$this->session->set_flashdata('pesan', 'Data Sukses Dihapus');
		redirect('admin_setting');
	}
}